<template>
  <div class="my-data">
    <NavBar :title="title" />
    <div class="content-top">
      <MyEmpty v-if="loading === false && list.length === 0" />
      <van-list v-model="loading" :finished="finish" finished-text="没有更多了" @load="onLoad" v-else>
        <van-swipe-cell class="list-item" v-for="(item, index) in list" :key="index">
          <div class="item-show01" @click="onCompanyClick(item.companyID)">
            <p>
              <span>{{ item.companyName }}</span>
              <span>{{ $dayjs(item.sawDate).format("MM-DD") }}</span>
            </p>
          </div>
          <template #right>
            <van-button square text="删除" type="danger" style="height: 100%" @click="onDel(index, item.id)" />
          </template>
        </van-swipe-cell>
      </van-list>
    </div>
  </div>
</template>

<script>
import {
  PersonLoginedGetWhoReadMeList,
  PersonLoginedDelWhoReadMe,
} from "@/util/http";
import NavBar from "@/components/NavBar.vue";
import MyEmpty from "@/components/MyEmpty.vue";
import { List, Toast, Dialog, SwipeCell, Button } from "vant";
import { mixin_person_toJobCompany } from "@/mixin/mixins";
export default {
  name: "WhoReadMe",
  components: {
    NavBar,
    MyEmpty,
    [List.name]: List,
    [SwipeCell.name]: SwipeCell,
    [Button.name]: Button,
  },
  props: ["title"],
  mixins: [mixin_person_toJobCompany],
  mounted() {
    this.onLoad();
  },
  // 定义属性
  data() {
    return {
      list: [],
      page: 0,
      loading: true,
      finish: false,
    };
  },
  // 方法集合
  methods: {
    onLoad() {
      this.loading = true;
      let page = this.page;
      page++;
      this.page = page;
      this.$api.get('/Resume/GetResumeReadedPageList', { pageIndex: this.page, pageSize: 50 }).then(res => {
        if (res.success) {
          this.loading = false;
          if (res.response.length > 0) {
            this.list = [...this.list, ...res.response];
          } else {
            this.finish = true;
          }
        }
      })
    },
    onDel(index, id) {
      Dialog.confirm({message: "确认删除该条记录？",}).then(() => {
          PersonLoginedDelWhoReadMe(id).then((res) => {
            Toast(res.msg);
            if (res.result === 1) {
              this.list.splice(index, 1);
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>

<style lang="less">
@import "vant/lib/dialog/index.less";
@import "@/assets/css/common.less";
@import "@/assets/css/person-my-job-list.css";
</style>
